function out = frameDec2(signal, level, HD)
%This program performs 2D framelet transform on a given signal.
%parameters:
%signal :  the input 2d signal. Type :2d matrix.
%level : .the level to decompsition. from 1 to any finite number. Type :int 
%HD :  the destruction filter. Type : cell. cell{1..N} denotes
%h0,h1,..hn-1.
%output:
%out : the framelet transform coefficients. Type : cell. each cell{i}
%denotes coefficients of level i.
nfilters = numel(HD);
[M N] = size(signal);
out = cell(1,level);
[mSignal nSignal] = size(signal);
K = 1;
while level > 0
    lenFilter = length(HD{1});
    cutrow = [];
    extSignal = [signal(:,nSignal - (lenFilter-3)/2 : nSignal) signal(:,:) signal(:,1:(lenFilter-1)/2)];
    for k = 1 : nfilters
        row = conv2(extSignal, HD{k});
        cutrow = [cutrow row(:,lenFilter : lenFilter-1+nSignal)];
    end
    
    cutcolumn = [];
    eextSignal = [cutrow(mSignal - (lenFilter-3)/2 : mSignal,:); cutrow(:,:) ; cutrow(1:(lenFilter-1)/2,:)];
    for k = 1 : nfilters
        column = conv2(eextSignal', HD{k})';
        cutcolumn = [cutcolumn ;column(lenFilter : lenFilter -1+mSignal, :)];
    end
    
    level = level -1;
    out{K} = cutcolumn;
    if level > 0
        out{K}(1:M,1:N) = 0;
    end
    signal = cutcolumn(1:M,1:N);
    HD = doubleFilter(HD);
    K = K +1;
end
end



